#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e5 + 10;

struct Node{
    int num, geshu;
}vis[N];

bool cmp(Node x, Node y){
    return x.geshu > y.geshu;
}
int t, d[N], v[N], a[N];
int p[N], lf[N];

signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while(t--){
        memset(lf, 0, sizeof lf);
        int n, m, l, v1, ans = 0;
        cin >> n >> m >> l >> v1;
        for(int i = 1; i <= n; i++){
            cin >> d[i] >> v[i] >> a[i];
        }
        for(int i = 1; i <= m; i++){
            cin >> p[i];
        }
        sort(p + 1, p + m + 1);
        for(int i = 1; i <= n; i++){
            bool flag = false;
            for(int j = 1; j <= m; j++){
                int dd = d[i];
                int vv = v[i];
                if(dd > p[j]) continue;
                bool tiqian = false;
                while(dd < p[j]){
                    vv = vv + a[i];
                    dd = dd + vv;
                    if(vv == 0){
                        tiqian = true;
                        break;
                    }
                }
                if(tiqian == true){
                    break;
                }
                if(vv > v1){
                    vis[p[j]].num = i;
                    vis[p[j]].geshu++;
                    if(flag == false){
                        ans = ans + 1;
                        flag = true;
                        lf[ans] = i;
                    }
                }
                if(dd >= p[m]) break;
            }
        }
        cout << ans << " ";
        int cnt = 0;
        bool c = false;
        sort(vis + 1, vis + m + 1, cmp);
        for(int i = 1; i <= m; i++){
            if(vis[p[i]].geshu == ans){
                cout << m - 1 << endl;
                c = true;
                break;
            } else{
                if(vis[p[i]].geshu != 0){
                    if(lf[vis[p[i]].num] != -1){
                        cnt++;
                        lf[vis[p[i]].num] = -1;
                    }
                }
            }
        }
        if(c == false) cout << m - cnt << endl;
    }
    return 0;
}
